#!/bin/bash

echo "Starting GuDB server in background..."
./bin/gudb-server -d /tmp/gudb_data -P 7777 -v > server.log 2>&1 &
SERVER_PID=$!

echo "Server started with PID: $SERVER_PID"
sleep 3

echo "Testing USE command..."
echo "USE isolation_test;" | ./bin/gu -h localhost -P 7777 -u admin

echo "Testing SHOW TABLES..."
echo "SHOW TABLES;" | ./bin/gu -h localhost -P 7777 -u admin

echo "Testing combined command..."
echo -e "USE isolation_test;\nSHOW TABLES;" | ./bin/gu -h localhost -P 7777 -u admin

echo "Stopping server..."
kill $SERVER_PID

echo "Server logs:"
cat server.log